<template>
  <div class="user-info">
    <el-dropdown>
      <span class="el-dropdown-link">
        <el-avatar :src="require('@/assets/img/97c5f4b34bdfda49bc2f09183166f37e.png')"></el-avatar>
        <span class="ml-10">{{ name }}</span>
        <!-- <arrow-down class="el-icon el-icon--right" /> -->
      </span>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item :icon="CirclePlus" @click="handleExitClick">退出登录</el-dropdown-item>
          <el-dropdown-item divided>用户信息</el-dropdown-item>
          <el-dropdown-item divided>菜单管理</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script lang="ts">
import { CirclePlus } from '@element-plus/icons-vue'
import { defineComponent, computed } from 'vue'
import { useStore } from '@/store'
import { useRouter } from 'vue-router'
import localCache from '@/utlis/cache'

export default defineComponent({
  setup() {
    const store = useStore()
    const name = computed(() => store.state.login.userInfo.name)

    const router = useRouter()
    const handleExitClick = () => {
      localCache.deleteCache('token')
      router.push('/main')
    }

    return { CirclePlus, name, handleExitClick }
  }
})
</script>

<style scoped>
.el-dropdown-link {
  cursor: pointer;
  display: flex;
  align-items: center;
}
.ml-10 {
  margin-left: 10px;
}
</style>
